package il.ac.technion.wiki.api.expressions;

import il.ac.technion.wiki.api.search.Hit;
import il.ac.technion.wiki.api.wikidocument.WikiDocument;
import il.ac.technion.wiki.impl.search.WikiIndexSearcher;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class OrOpTest {

	@Test
	public void testEvaluate() {
		WikiIndexSearcher mis = new WikiIndexSearcher();
		createDocs(mis);
		OrOp and = new OrOp();
		and.setElements(new Term("b"), new Term("c"));
		List<Hit> hits = and.getHits(mis);
		Hit hit = hits.get(0);
		Assert.assertEquals("3", hit.docTitle);
		hit = hits.get(1);
		Assert.assertEquals("4", hit.docTitle);
		hit = hits.get(2);
		Assert.assertEquals("1", hit.docTitle);
		Assert.assertEquals(3, hits.size());
	}
	
	private void createDocs(WikiIndexSearcher mis){
		mis.addDocument(new WikiDocument("1" , "f f g d d b"));
		mis.addDocument(new WikiDocument("2" , "fff  f"));
		mis.addDocument(new WikiDocument("3" , "c c c b b"));
		mis.addDocument(new WikiDocument("4" , "d d d c c"));
	}
}
